var express = require('express');

var app = express();

const fs = require('fs');
const path = require('path');

// 指定文件夹路径
const folderPath = path.join(__dirname, 'htdocs');
var filelistPath=[]
fs.readdir(folderPath, (err, files) => {
  if (err) {
    return console.error('Error reading directory', err);
  }
  // 输出文件名称列表
  files.forEach(element => {
    let obj={fileName:element,filePath:'http://127.0.0.1:3000/'+element}
    //console.log(obj)
    filelistPath.push(obj)
  });
  console.log(filelistPath)
  
});

app.use(express.static('./htdocs'));
app.get('/list', function (req, res) {
  res.json(filelistPath);
});
app.listen(3000, res => {
  console.log('服务器启动成功，访问地址：http://127.0.0.1:3000/文件名');
});
